
//
//  TBComposeTextView.swift
//  新浪微博
//
//  Created by bin on 16/2/3.
//  Copyright © 2016年 XMG. All rights reserved.
//

import UIKit

class TBComposeTextView: UITextView {

    init() {
        super.init(frame: CGRectZero, textContainer: nil)
        setupPlaceholder()
        
    }
    
    deinit{
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupPlaceholder()
    }
    
    //MARK: - 内部控制方法
    
    private func setupPlaceholder(){
        NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("textViewTextDidChange"), name: UITextViewTextDidChangeNotification, object: self)
        addSubview(placeholderLabel)
        placeholderLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(5)
            make.top.equalTo(8)
        }

    }
    
    @objc private func textViewTextDidChange(){

        placeholderLabel.hidden = hasText()
    }

    //MARK: - 懒加载
    
    lazy var placeholderLabel: UILabel = {
        let lb = UILabel()
        lb.text = "分享新鲜事..."
        lb.textColor = UIColor.lightGrayColor()
        lb.font = self.font
        return lb
    }()
}
